package neusoft.example.com.yuejian06.Model;

import java.util.List;

import neusoft.example.com.yuejian06.Bean.Comment;
import neusoft.example.com.yuejian06.Bean.Picture;
import neusoft.example.com.yuejian06.PublicActivity;
import neusoft.example.com.yuejian06.RetrofitListener;
import neusoft.example.com.yuejian06.Service.PictureService;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class PictureCommentListModel {
    private  PublicActivity publicActivity;
    private Retrofit retrofit;
    private PictureService service;

    public PictureCommentListModel(){
        publicActivity= new PublicActivity();
        retrofit=new Retrofit.Builder()
                .baseUrl(publicActivity.getIp()+"api/Comment/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        service = retrofit.create(PictureService.class);

    }
    //评论列表
    public void getCommentList(String picture_id,final RetrofitListener<List<Comment>> listener){
        Call<List<Comment>> call = service.getCommentList(picture_id);
        call.enqueue(new Callback<List<Comment>>(){

            @Override
            public void onResponse(Call<List<Comment>> call, Response<List<Comment>> response) {
                if(response.isSuccessful() && response!=null){
                    listener.onResponse(response.body());
                }else{
                    listener.onFail("服务器炸了！");//
                }
            }

            @Override
            public void onFailure(Call<List<Comment>> call, Throwable t) {
                listener .onFail(t.toString());
            }
        });
    }


}
